{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>AGE</th>\n",
       "      <th>GENDER</th>\n",
       "      <th>MARRIAGE</th>\n",
       "      <th>EDU_EXPERIENCE</th>\n",
       "      <th>WORK_SIZE</th>\n",
       "      <th>WORK_POWER</th>\n",
       "      <th>IS_ILLEGAL_HIS</th>\n",
       "      <th>CURR_FREEZE_VALUE</th>\n",
       "      <th>GRADUATE_YEAR</th>\n",
       "      <th>OCCUPATION</th>\n",
       "      <th>OCCUPATION_TYPE</th>\n",
       "      <th>VIP_FLAG</th>\n",
       "      <th>GRAY_FLAG</th>\n",
       "      <th>FIVE_CLASS_TYPE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>15735</th>\n",
       "      <td>51</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>99</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15741</th>\n",
       "      <td>56</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>60</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15753</th>\n",
       "      <td>45</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>70</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>9</td>\n",
       "      <td>z</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15788</th>\n",
       "      <td>41</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>70</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>9</td>\n",
       "      <td>z</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15797</th>\n",
       "      <td>42</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>70</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       AGE  GENDER  MARRIAGE  EDU_EXPERIENCE  WORK_SIZE  WORK_POWER  \\\n",
       "15735   51       1         2              99          2           1   \n",
       "15741   56       1         2              60          2           1   \n",
       "15753   45       1         2              70          2           1   \n",
       "15788   41       1         2              70          2           1   \n",
       "15797   42       1         3              70          3           1   \n",
       "\n",
       "       IS_ILLEGAL_HIS  CURR_FREEZE_VALUE  GRADUATE_YEAR  OCCUPATION  \\\n",
       "15735             2.0                0.0            4.0           9   \n",
       "15741             2.0                0.0            4.0           9   \n",
       "15753             2.0                0.0            3.0           9   \n",
       "15788             2.0                0.0            4.0           9   \n",
       "15797             2.0                0.0            4.0           9   \n",
       "\n",
       "      OCCUPATION_TYPE  VIP_FLAG  GRAY_FLAG  FIVE_CLASS_TYPE  \n",
       "15735               5         0          0                0  \n",
       "15741               5         0          0                0  \n",
       "15753               z         0          0                0  \n",
       "15788               z         0          0                0  \n",
       "15797               5         0          0                1  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "file_path = './test2.csv'\n",
    "data = pd.read_csv(file_path,index_col=0)\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((504, 10), (504,))"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "numerical = ['AGE', 'WORK_SIZE', 'CURR_FREEZE_VALUE', 'GRADUATE_YEAR']\n",
    "\n",
    "categorical = ['EDU_EXPERIENCE', 'MARRIAGE', 'OCCUPATION', 'OCCUPATION_TYPE']\n",
    "\n",
    "binary = ['GENDER', 'WORK_POWER']\n",
    "\n",
    "train_X = data[numerical + categorical + binary]\n",
    "train_Y = data['FIVE_CLASS_TYPE']\n",
    "\n",
    "train_X.shape,train_Y.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "字段|中文|类型\n",
    "--|--|--\n",
    "AGE|年龄|数值\n",
    "WORK_SIZE|劳动人口数|数值\n",
    "CURR_FREEZE_VALUE|账户冻结金额|数值\n",
    "GRADUATE_YEAR|工作年限|数值\n",
    "EDU_EXPERIENCE|最高学历|类别\n",
    "MARRIAGE|结婚|类别\n",
    "OCCUPATION|职务|类别\n",
    "OCCUPATION_TYPE|职业类型|类别\n",
    "GENDER|性别|二值\n",
    "WORK_POWER|劳动能力|二值\n",
    "IS_ILLEGAL_HIS|是否非法|删除\n",
    "VIP_FLAG|白名单客户|删除\n",
    "GRAY_FLAG|灰名单客户|删除\n",
    "FIVE_CLASS_TYPE|五级分类|目标值\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 类别型变量进行One-hot编码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EDU_EXPERIENCE_10</th>\n",
       "      <th>EDU_EXPERIENCE_20</th>\n",
       "      <th>EDU_EXPERIENCE_30</th>\n",
       "      <th>EDU_EXPERIENCE_40</th>\n",
       "      <th>EDU_EXPERIENCE_50</th>\n",
       "      <th>EDU_EXPERIENCE_60</th>\n",
       "      <th>EDU_EXPERIENCE_70</th>\n",
       "      <th>EDU_EXPERIENCE_80</th>\n",
       "      <th>EDU_EXPERIENCE_90</th>\n",
       "      <th>EDU_EXPERIENCE_99</th>\n",
       "      <th>...</th>\n",
       "      <th>OCCUPATION_4</th>\n",
       "      <th>OCCUPATION_9</th>\n",
       "      <th>OCCUPATION_TYPE_0</th>\n",
       "      <th>OCCUPATION_TYPE_1</th>\n",
       "      <th>OCCUPATION_TYPE_3</th>\n",
       "      <th>OCCUPATION_TYPE_4</th>\n",
       "      <th>OCCUPATION_TYPE_5</th>\n",
       "      <th>OCCUPATION_TYPE_6</th>\n",
       "      <th>OCCUPATION_TYPE_y</th>\n",
       "      <th>OCCUPATION_TYPE_z</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>15735</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15741</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15753</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15788</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15797</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 27 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       EDU_EXPERIENCE_10  EDU_EXPERIENCE_20  EDU_EXPERIENCE_30  \\\n",
       "15735                  0                  0                  0   \n",
       "15741                  0                  0                  0   \n",
       "15753                  0                  0                  0   \n",
       "15788                  0                  0                  0   \n",
       "15797                  0                  0                  0   \n",
       "\n",
       "       EDU_EXPERIENCE_40  EDU_EXPERIENCE_50  EDU_EXPERIENCE_60  \\\n",
       "15735                  0                  0                  0   \n",
       "15741                  0                  0                  1   \n",
       "15753                  0                  0                  0   \n",
       "15788                  0                  0                  0   \n",
       "15797                  0                  0                  0   \n",
       "\n",
       "       EDU_EXPERIENCE_70  EDU_EXPERIENCE_80  EDU_EXPERIENCE_90  \\\n",
       "15735                  0                  0                  0   \n",
       "15741                  0                  0                  0   \n",
       "15753                  1                  0                  0   \n",
       "15788                  1                  0                  0   \n",
       "15797                  1                  0                  0   \n",
       "\n",
       "       EDU_EXPERIENCE_99        ...          OCCUPATION_4  OCCUPATION_9  \\\n",
       "15735                  1        ...                     0             1   \n",
       "15741                  0        ...                     0             1   \n",
       "15753                  0        ...                     0             1   \n",
       "15788                  0        ...                     0             1   \n",
       "15797                  0        ...                     0             1   \n",
       "\n",
       "       OCCUPATION_TYPE_0  OCCUPATION_TYPE_1  OCCUPATION_TYPE_3  \\\n",
       "15735                  0                  0                  0   \n",
       "15741                  0                  0                  0   \n",
       "15753                  0                  0                  0   \n",
       "15788                  0                  0                  0   \n",
       "15797                  0                  0                  0   \n",
       "\n",
       "       OCCUPATION_TYPE_4  OCCUPATION_TYPE_5  OCCUPATION_TYPE_6  \\\n",
       "15735                  0                  1                  0   \n",
       "15741                  0                  1                  0   \n",
       "15753                  0                  0                  0   \n",
       "15788                  0                  0                  0   \n",
       "15797                  0                  1                  0   \n",
       "\n",
       "       OCCUPATION_TYPE_y  OCCUPATION_TYPE_z  \n",
       "15735                  0                  0  \n",
       "15741                  0                  0  \n",
       "15753                  0                  1  \n",
       "15788                  0                  1  \n",
       "15797                  0                  0  \n",
       "\n",
       "[5 rows x 27 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_dummies = pd.get_dummies(data[categorical],columns=categorical)\n",
    "data_dummies.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(504, 34)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_X = pd.concat([data[numerical+binary],data_dummies],axis=1)\n",
    "train = pd.concat([train_X,train_Y],axis=1)\n",
    "train.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 获取卡方值\n",
    "对年龄做探索性的分箱\n",
    "\n",
    "命中率，最理想的样本选择命中率是3：1~5：1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.24404761904761904"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pos_cnt = train_Y.sum()   # 命中率(坏人)\n",
    "all_cnt = train_Y.count() # 所有人\n",
    "expected_ratio = float(pos_cnt)/all_cnt\n",
    "expected_ratio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "col = 'AGE'\n",
    "target = 'FIVE_CLASS_TYPE'\n",
    "df = train[[col,target]]\n",
    "df=df.dropna()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "def cal_woe(row,good,bad):\n",
    "    yi=0.01 if row['hit']==0 else row['hit']\n",
    "    ni=row['all']-row['hit']\n",
    "    ni=0.02 if ni==0 else ni\n",
    "    return np.log((yi/bad)/(ni/good))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def cal_iv(row,good,bad):\n",
    "    yi=0.01 if row['hit']==0 else row['hit']\n",
    "    ni=row['all']-row['hit']\n",
    "    ni=0.02 if ni==0 else ni\n",
    "    return (yi/bad-ni/good)*row['woe']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def merge_shiSquare(df_count,minIndex,mergeIndex,col='AGE'):\n",
    "    df_count[col]= df_count[col].astype(np.str)\n",
    "    col_name=df_count.loc[minIndex,col]+\"~\"+df_count.loc[mergeIndex,col] # 将列名拼接\n",
    "    col_names=col_name.split(\"~\") # 切分成列表\n",
    "    col_names=[float(n) for n in col_names] # 转成数值用来排序\n",
    "    col_names.sort() # 排序\n",
    "    df_count.loc[mergeIndex,col]= str(col_names[0])+\"~\"+str(col_names[-1]); # 把最大值和最小值拼接成表签名\n",
    "    for c in ('count', 'hit', 'all', 'expected_cnt'): \n",
    "        df_count.loc[mergeIndex,c]+=df_count.loc[minIndex,c] # 所有列的值相加\n",
    "    # 卡方值重新计算\n",
    "    df_count.loc[mergeIndex,'chi_sequare']=(df_count.loc[mergeIndex,'hit']-df_count.loc[mergeIndex,'expected_cnt'])**2/df_count.loc[mergeIndex,'expected_cnt']\n",
    "    df_count.drop(index=minIndex,inplace=True) # 删除被合并的值\n",
    "    #df_count=df_count.reset_index()\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def chi_sequare_cal(hit,expected_count):\n",
    "    return (hit-expected_count)**2/expected_count\n",
    "\n",
    "def handerCol(df,col,target,maxInterval=5):\n",
    "    df_count = df[col].value_counts().sort_index().reset_index().rename(columns={\"index\":col,col:\"count\"})\n",
    "    df_count['hit']=df_count.apply(lambda a:train.loc[train[col]==a[col],target].sum(),axis=1)\n",
    "    df_count['all']=df_count.apply(lambda a:train.loc[train[col]==a[col],target].count(),axis=1)\n",
    "    df_count['expected_cnt']=df_count['all']*expected_ratio\n",
    "    df_count['chi_sequare']=df_count.apply(lambda row:chi_sequare_cal(row['hit'],row['expected_cnt']),axis=1)\n",
    "\n",
    "    \n",
    "    while df_count.shape[0]>maxInterval: # 保存5个分箱\n",
    "        min_index = df_count[df_count['chi_sequare']==df_count['chi_sequare'].min()].index.tolist()[0] # 最小值索引\n",
    "        if min_index>0 and min_index<df_count.shape[0] and min_index<df_count.shape[0]-1:\n",
    "            diff_sqr_val = df_count.loc[min_index-1,'chi_sequare']-df_count.loc[min_index+1,'chi_sequare'] # 根据卡方值确定合并上一行还是下一行\n",
    "        if min_index==0 or diff_sqr_val>0 and min_index<df_count.shape[0]-1: # 合并的索引号\n",
    "            merge_index = min_index+1\n",
    "        else :\n",
    "            merge_index = min_index-1\n",
    "        merge_shiSquare(df_count,min_index,merge_index,col) # 合并分箱\n",
    "        df_count.index=range(df_count.shape[0]) # 重置索引\n",
    "    [good,bad]=list(data[target].value_counts())\n",
    "    df_count['woe']=df_count.apply(cal_woe,axis=1,args=(good,bad))\n",
    "    df_count['iv']=df_count.apply(cal_iv,axis=1,args=(good,bad))\n",
    "    return df_count\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>AGE</th>\n",
       "      <th>count</th>\n",
       "      <th>hit</th>\n",
       "      <th>all</th>\n",
       "      <th>expected_cnt</th>\n",
       "      <th>chi_sequare</th>\n",
       "      <th>woe</th>\n",
       "      <th>iv</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>21.0~22.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0.488095</td>\n",
       "      <td>0.536876</td>\n",
       "      <td>1.130615</td>\n",
       "      <td>0.006224</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>23.0~27.0</td>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>8</td>\n",
       "      <td>1.952381</td>\n",
       "      <td>0.464576</td>\n",
       "      <td>-0.815295</td>\n",
       "      <td>0.008351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>28.0~57.0</td>\n",
       "      <td>467</td>\n",
       "      <td>110</td>\n",
       "      <td>467</td>\n",
       "      <td>113.970238</td>\n",
       "      <td>0.138306</td>\n",
       "      <td>-0.046640</td>\n",
       "      <td>0.001991</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>58</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>9</td>\n",
       "      <td>2.196429</td>\n",
       "      <td>3.578542</td>\n",
       "      <td>1.353759</td>\n",
       "      <td>0.040818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>59.0~75.0</td>\n",
       "      <td>18</td>\n",
       "      <td>6</td>\n",
       "      <td>18</td>\n",
       "      <td>4.392857</td>\n",
       "      <td>0.587979</td>\n",
       "      <td>0.437468</td>\n",
       "      <td>0.007561</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         AGE  count  hit  all  expected_cnt  chi_sequare       woe        iv\n",
       "0  21.0~22.0      2    1    2      0.488095     0.536876  1.130615  0.006224\n",
       "1  23.0~27.0      8    1    8      1.952381     0.464576 -0.815295  0.008351\n",
       "2  28.0~57.0    467  110  467    113.970238     0.138306 -0.046640  0.001991\n",
       "3         58      9    5    9      2.196429     3.578542  1.353759  0.040818\n",
       "4  59.0~75.0     18    6   18      4.392857     0.587979  0.437468  0.007561"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_count = handerCol(df,col,target,5).head()\n",
    "df_count.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 分箱合并"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "def split_box(data,col,num=5):\n",
    "    df_cnt_tmp=handerCol(data,col,target,num)\n",
    "    df_cnt_tmp['t']=col\n",
    "    df_cnt_tmp['iv_mount']=df_cnt_tmp['iv'].sum()\n",
    "    return df_cnt_tmp.rename(columns={col:\"box\"})\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "连续型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "boxs = []\n",
    "for c in numerical:\n",
    "    boxs.append(split_box(data,c,5))\n",
    "#split_box_rst=pd.concat(boxs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "二值型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "for c in binary:\n",
    "    boxs.append(split_box(data,c,5))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "one-hot编码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "for c in data_dummies.columns:\n",
    "    boxs.append(split_box(data_dummies,c,5))\n",
    "split_box_rst=pd.concat(boxs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 筛选处iv值大于0.02的变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>box</th>\n",
       "      <th>count</th>\n",
       "      <th>hit</th>\n",
       "      <th>all</th>\n",
       "      <th>expected_cnt</th>\n",
       "      <th>chi_sequare</th>\n",
       "      <th>woe</th>\n",
       "      <th>iv</th>\n",
       "      <th>t</th>\n",
       "      <th>iv_mount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>21.0~22.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0.488095</td>\n",
       "      <td>0.536876</td>\n",
       "      <td>1.130615</td>\n",
       "      <td>0.006224</td>\n",
       "      <td>AGE</td>\n",
       "      <td>0.064946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>23.0~27.0</td>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>8</td>\n",
       "      <td>1.952381</td>\n",
       "      <td>0.464576</td>\n",
       "      <td>-0.815295</td>\n",
       "      <td>0.008351</td>\n",
       "      <td>AGE</td>\n",
       "      <td>0.064946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>28.0~57.0</td>\n",
       "      <td>467</td>\n",
       "      <td>110</td>\n",
       "      <td>467</td>\n",
       "      <td>113.970238</td>\n",
       "      <td>0.138306</td>\n",
       "      <td>-0.046640</td>\n",
       "      <td>0.001991</td>\n",
       "      <td>AGE</td>\n",
       "      <td>0.064946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>58</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>9</td>\n",
       "      <td>2.196429</td>\n",
       "      <td>3.578542</td>\n",
       "      <td>1.353759</td>\n",
       "      <td>0.040818</td>\n",
       "      <td>AGE</td>\n",
       "      <td>0.064946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>59.0~75.0</td>\n",
       "      <td>18</td>\n",
       "      <td>6</td>\n",
       "      <td>18</td>\n",
       "      <td>4.392857</td>\n",
       "      <td>0.587979</td>\n",
       "      <td>0.437468</td>\n",
       "      <td>0.007561</td>\n",
       "      <td>AGE</td>\n",
       "      <td>0.064946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0~10000.0</td>\n",
       "      <td>386</td>\n",
       "      <td>105</td>\n",
       "      <td>386</td>\n",
       "      <td>94.202381</td>\n",
       "      <td>1.237639</td>\n",
       "      <td>0.146221</td>\n",
       "      <td>0.016980</td>\n",
       "      <td>CURR_FREEZE_VALUE</td>\n",
       "      <td>0.248174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>15000.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.244048</td>\n",
       "      <td>2.341609</td>\n",
       "      <td>5.042638</td>\n",
       "      <td>0.040732</td>\n",
       "      <td>CURR_FREEZE_VALUE</td>\n",
       "      <td>0.248174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20000.0</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>2.196429</td>\n",
       "      <td>2.196429</td>\n",
       "      <td>-5.671780</td>\n",
       "      <td>0.133518</td>\n",
       "      <td>CURR_FREEZE_VALUE</td>\n",
       "      <td>0.248174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>30000.0~98000.0</td>\n",
       "      <td>72</td>\n",
       "      <td>12</td>\n",
       "      <td>72</td>\n",
       "      <td>17.571429</td>\n",
       "      <td>1.766551</td>\n",
       "      <td>-0.478823</td>\n",
       "      <td>0.028691</td>\n",
       "      <td>CURR_FREEZE_VALUE</td>\n",
       "      <td>0.248174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>100000.0~500000.0</td>\n",
       "      <td>36</td>\n",
       "      <td>5</td>\n",
       "      <td>36</td>\n",
       "      <td>8.785714</td>\n",
       "      <td>1.631243</td>\n",
       "      <td>-0.693934</td>\n",
       "      <td>0.028253</td>\n",
       "      <td>CURR_FREEZE_VALUE</td>\n",
       "      <td>0.248174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>502</td>\n",
       "      <td>123</td>\n",
       "      <td>502</td>\n",
       "      <td>122.511905</td>\n",
       "      <td>0.001945</td>\n",
       "      <td>0.005263</td>\n",
       "      <td>0.000028</td>\n",
       "      <td>EDU_EXPERIENCE_10</td>\n",
       "      <td>0.021566</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.488095</td>\n",
       "      <td>0.488095</td>\n",
       "      <td>-4.167702</td>\n",
       "      <td>0.021539</td>\n",
       "      <td>EDU_EXPERIENCE_10</td>\n",
       "      <td>0.021566</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>476</td>\n",
       "      <td>120</td>\n",
       "      <td>476</td>\n",
       "      <td>116.166667</td>\n",
       "      <td>0.126495</td>\n",
       "      <td>0.043176</td>\n",
       "      <td>0.001780</td>\n",
       "      <td>EDU_EXPERIENCE_20</td>\n",
       "      <td>0.042580</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>28</td>\n",
       "      <td>3</td>\n",
       "      <td>28</td>\n",
       "      <td>6.833333</td>\n",
       "      <td>2.150407</td>\n",
       "      <td>-0.989649</td>\n",
       "      <td>0.040800</td>\n",
       "      <td>EDU_EXPERIENCE_20</td>\n",
       "      <td>0.042580</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>347</td>\n",
       "      <td>75</td>\n",
       "      <td>347</td>\n",
       "      <td>84.684524</td>\n",
       "      <td>1.107522</td>\n",
       "      <td>-0.157699</td>\n",
       "      <td>0.016425</td>\n",
       "      <td>EDU_EXPERIENCE_70</td>\n",
       "      <td>0.048762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>157</td>\n",
       "      <td>48</td>\n",
       "      <td>157</td>\n",
       "      <td>38.315476</td>\n",
       "      <td>2.447836</td>\n",
       "      <td>0.310468</td>\n",
       "      <td>0.032337</td>\n",
       "      <td>EDU_EXPERIENCE_70</td>\n",
       "      <td>0.048762</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>409</td>\n",
       "      <td>109</td>\n",
       "      <td>409</td>\n",
       "      <td>99.815476</td>\n",
       "      <td>0.845114</td>\n",
       "      <td>0.118180</td>\n",
       "      <td>0.011674</td>\n",
       "      <td>EDU_EXPERIENCE_99</td>\n",
       "      <td>0.073387</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>95</td>\n",
       "      <td>14</td>\n",
       "      <td>95</td>\n",
       "      <td>23.184524</td>\n",
       "      <td>3.638439</td>\n",
       "      <td>-0.624777</td>\n",
       "      <td>0.061714</td>\n",
       "      <td>EDU_EXPERIENCE_99</td>\n",
       "      <td>0.073387</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>497</td>\n",
       "      <td>119</td>\n",
       "      <td>497</td>\n",
       "      <td>121.291667</td>\n",
       "      <td>0.043298</td>\n",
       "      <td>-0.025156</td>\n",
       "      <td>0.000620</td>\n",
       "      <td>OCCUPATION_1</td>\n",
       "      <td>0.035576</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>7</td>\n",
       "      <td>1.708333</td>\n",
       "      <td>3.074187</td>\n",
       "      <td>1.418297</td>\n",
       "      <td>0.034956</td>\n",
       "      <td>OCCUPATION_1</td>\n",
       "      <td>0.035576</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>488</td>\n",
       "      <td>115</td>\n",
       "      <td>488</td>\n",
       "      <td>119.095238</td>\n",
       "      <td>0.140820</td>\n",
       "      <td>-0.046031</td>\n",
       "      <td>0.002027</td>\n",
       "      <td>OCCUPATION_TYPE_1</td>\n",
       "      <td>0.051823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>16</td>\n",
       "      <td>8</td>\n",
       "      <td>16</td>\n",
       "      <td>3.904762</td>\n",
       "      <td>4.295006</td>\n",
       "      <td>1.130615</td>\n",
       "      <td>0.049796</td>\n",
       "      <td>OCCUPATION_TYPE_1</td>\n",
       "      <td>0.051823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>453</td>\n",
       "      <td>117</td>\n",
       "      <td>453</td>\n",
       "      <td>110.553571</td>\n",
       "      <td>0.375894</td>\n",
       "      <td>0.075678</td>\n",
       "      <td>0.005247</td>\n",
       "      <td>OCCUPATION_TYPE_3</td>\n",
       "      <td>0.066554</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>51</td>\n",
       "      <td>6</td>\n",
       "      <td>51</td>\n",
       "      <td>12.446429</td>\n",
       "      <td>3.338825</td>\n",
       "      <td>-0.884288</td>\n",
       "      <td>0.061307</td>\n",
       "      <td>OCCUPATION_TYPE_3</td>\n",
       "      <td>0.066554</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>452</td>\n",
       "      <td>116</td>\n",
       "      <td>452</td>\n",
       "      <td>110.309524</td>\n",
       "      <td>0.293551</td>\n",
       "      <td>0.067094</td>\n",
       "      <td>0.004106</td>\n",
       "      <td>OCCUPATION_TYPE_4</td>\n",
       "      <td>0.048790</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>52</td>\n",
       "      <td>7</td>\n",
       "      <td>52</td>\n",
       "      <td>12.690476</td>\n",
       "      <td>2.551639</td>\n",
       "      <td>-0.730137</td>\n",
       "      <td>0.044684</td>\n",
       "      <td>OCCUPATION_TYPE_4</td>\n",
       "      <td>0.048790</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>275</td>\n",
       "      <td>53</td>\n",
       "      <td>275</td>\n",
       "      <td>67.113095</td>\n",
       "      <td>2.967818</td>\n",
       "      <td>-0.301770</td>\n",
       "      <td>0.045804</td>\n",
       "      <td>OCCUPATION_TYPE_5</td>\n",
       "      <td>0.092888</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>229</td>\n",
       "      <td>70</td>\n",
       "      <td>229</td>\n",
       "      <td>55.886905</td>\n",
       "      <td>3.563974</td>\n",
       "      <td>0.310206</td>\n",
       "      <td>0.047084</td>\n",
       "      <td>OCCUPATION_TYPE_5</td>\n",
       "      <td>0.092888</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>426</td>\n",
       "      <td>110</td>\n",
       "      <td>426</td>\n",
       "      <td>103.964286</td>\n",
       "      <td>0.350407</td>\n",
       "      <td>0.075353</td>\n",
       "      <td>0.004891</td>\n",
       "      <td>OCCUPATION_TYPE_z</td>\n",
       "      <td>0.035973</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>78</td>\n",
       "      <td>13</td>\n",
       "      <td>78</td>\n",
       "      <td>19.035714</td>\n",
       "      <td>1.913763</td>\n",
       "      <td>-0.478823</td>\n",
       "      <td>0.031082</td>\n",
       "      <td>OCCUPATION_TYPE_z</td>\n",
       "      <td>0.035973</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 box  count  hit  all  expected_cnt  chi_sequare       woe  \\\n",
       "0          21.0~22.0      2    1    2      0.488095     0.536876  1.130615   \n",
       "1          23.0~27.0      8    1    8      1.952381     0.464576 -0.815295   \n",
       "2          28.0~57.0    467  110  467    113.970238     0.138306 -0.046640   \n",
       "3                 58      9    5    9      2.196429     3.578542  1.353759   \n",
       "4          59.0~75.0     18    6   18      4.392857     0.587979  0.437468   \n",
       "0        0.0~10000.0    386  105  386     94.202381     1.237639  0.146221   \n",
       "1            15000.0      1    1    1      0.244048     2.341609  5.042638   \n",
       "2            20000.0      9    0    9      2.196429     2.196429 -5.671780   \n",
       "3    30000.0~98000.0     72   12   72     17.571429     1.766551 -0.478823   \n",
       "4  100000.0~500000.0     36    5   36      8.785714     1.631243 -0.693934   \n",
       "0                  0    502  123  502    122.511905     0.001945  0.005263   \n",
       "1                  1      2    0    2      0.488095     0.488095 -4.167702   \n",
       "0                  0    476  120  476    116.166667     0.126495  0.043176   \n",
       "1                  1     28    3   28      6.833333     2.150407 -0.989649   \n",
       "0                  0    347   75  347     84.684524     1.107522 -0.157699   \n",
       "1                  1    157   48  157     38.315476     2.447836  0.310468   \n",
       "0                  0    409  109  409     99.815476     0.845114  0.118180   \n",
       "1                  1     95   14   95     23.184524     3.638439 -0.624777   \n",
       "0                  0    497  119  497    121.291667     0.043298 -0.025156   \n",
       "1                  1      7    4    7      1.708333     3.074187  1.418297   \n",
       "0                  0    488  115  488    119.095238     0.140820 -0.046031   \n",
       "1                  1     16    8   16      3.904762     4.295006  1.130615   \n",
       "0                  0    453  117  453    110.553571     0.375894  0.075678   \n",
       "1                  1     51    6   51     12.446429     3.338825 -0.884288   \n",
       "0                  0    452  116  452    110.309524     0.293551  0.067094   \n",
       "1                  1     52    7   52     12.690476     2.551639 -0.730137   \n",
       "0                  0    275   53  275     67.113095     2.967818 -0.301770   \n",
       "1                  1    229   70  229     55.886905     3.563974  0.310206   \n",
       "0                  0    426  110  426    103.964286     0.350407  0.075353   \n",
       "1                  1     78   13   78     19.035714     1.913763 -0.478823   \n",
       "\n",
       "         iv                  t  iv_mount  \n",
       "0  0.006224                AGE  0.064946  \n",
       "1  0.008351                AGE  0.064946  \n",
       "2  0.001991                AGE  0.064946  \n",
       "3  0.040818                AGE  0.064946  \n",
       "4  0.007561                AGE  0.064946  \n",
       "0  0.016980  CURR_FREEZE_VALUE  0.248174  \n",
       "1  0.040732  CURR_FREEZE_VALUE  0.248174  \n",
       "2  0.133518  CURR_FREEZE_VALUE  0.248174  \n",
       "3  0.028691  CURR_FREEZE_VALUE  0.248174  \n",
       "4  0.028253  CURR_FREEZE_VALUE  0.248174  \n",
       "0  0.000028  EDU_EXPERIENCE_10  0.021566  \n",
       "1  0.021539  EDU_EXPERIENCE_10  0.021566  \n",
       "0  0.001780  EDU_EXPERIENCE_20  0.042580  \n",
       "1  0.040800  EDU_EXPERIENCE_20  0.042580  \n",
       "0  0.016425  EDU_EXPERIENCE_70  0.048762  \n",
       "1  0.032337  EDU_EXPERIENCE_70  0.048762  \n",
       "0  0.011674  EDU_EXPERIENCE_99  0.073387  \n",
       "1  0.061714  EDU_EXPERIENCE_99  0.073387  \n",
       "0  0.000620       OCCUPATION_1  0.035576  \n",
       "1  0.034956       OCCUPATION_1  0.035576  \n",
       "0  0.002027  OCCUPATION_TYPE_1  0.051823  \n",
       "1  0.049796  OCCUPATION_TYPE_1  0.051823  \n",
       "0  0.005247  OCCUPATION_TYPE_3  0.066554  \n",
       "1  0.061307  OCCUPATION_TYPE_3  0.066554  \n",
       "0  0.004106  OCCUPATION_TYPE_4  0.048790  \n",
       "1  0.044684  OCCUPATION_TYPE_4  0.048790  \n",
       "0  0.045804  OCCUPATION_TYPE_5  0.092888  \n",
       "1  0.047084  OCCUPATION_TYPE_5  0.092888  \n",
       "0  0.004891  OCCUPATION_TYPE_z  0.035973  \n",
       "1  0.031082  OCCUPATION_TYPE_z  0.035973  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "split_box_rst.loc[split_box_rst['iv_mount'].map(lambda r:r>0.02)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
